home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / DesktopDoubler / Loader / Loader.c next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  1.4 KB  |  84 lines  |  [TEXT/CWIE]

  1. #define DISABLE_LOCAL_CALLTRACE        1        // Set to 1 to disable Call Traces for this file.
  2. #define DISABLE_LOCAL_DEBUG            0        // Set to 1 to disable all debugging for this file.
  3. #include "DebugUtils.h"
  4.  
  5. #include <Resources.h>
  6. #include "ContextUtils.h"
  7. #include "Nub.h"
  8.  
  9.  
  10.  
  11.  
  12.  
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16.  
  17. OSStatus main(void);
  18. static Boolean isPressed(UInt8 keyCode);
  19.  
  20. #ifdef __cplusplus
  21. }
  22. #endif
  23.  
  24.  
  25. #define CONTROL_KEY        0x3B
  26. #define OPTION_KEY        0x3A
  27. #define D_KEY            0x02
  28. #define S_KEY            0x01
  29.  
  30.  
  31.  
  32.  
  33.  
  34. OSStatus main(void)
  35. {
  36.     GlobalContext    globals;
  37.     THzContext        zone(SystemZone());
  38.     Handle            code;
  39.     OSStatus        err;
  40.     
  41.     
  42.     // Check and break.
  43.     #if DEBUG
  44.         if (isPressed(CONTROL_KEY) && isPressed(OPTION_KEY) && isPressed(D_KEY) && isPressed(S_KEY))
  45.             DebugStr("\pNub> Thank you for holding down CONTROL-OPTION-D-S");
  46.     #endif
  47.     
  48.     // Load the nub code resource.
  49.     code = Get1Resource('nub ',0);
  50.     if (code == NULL)
  51.     {
  52.         dprintf(kDConPrefix "Get1Resource('nub ',0) failed: %ld\n",ResError());
  53.         return -1;
  54.     }
  55.     
  56.     // Detach and lock code resource
  57.     // so we can safely call it.
  58.     DetachResource(code);
  59.     HLock(code);
  60.     
  61.     // Call the main entry point.
  62.     err = CallNubLoadProc((NubLoadUPP)(*code),code);
  63.     if (err != noErr)
  64.     {
  65.         dprintf(kDConPrefix "NubLoad failed: %ld  %s:%d\n",err);
  66.         DisposeHandle(code);
  67.     }
  68.     
  69.     return err;
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76. Boolean isPressed(UInt8 keyCode)
  77. {
  78.     UInt8    km[16];
  79.     
  80.     
  81.     GetKeys((SInt32*)&km[0]);
  82.     return ((km[keyCode >> 3] >> (keyCode & 7)) & 1);
  83. }
  84.